/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/3/22
 * \* Time: 14:16
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class Demo10 {

    private static boolean isQuit = false;

    public static void main(String[] args) {
        Thread t = new Thread(()->{
           while(!isQuit) {
               System.out.println("hello world!");
               try {
                   Thread.sleep(5000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        t.start();
        //isQuit 为true，则此时循环退出，进一步run就执行完了，进一步则线程执行结束
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        isQuit = true;
        System.out.println("终止t线程");
    }
}
